package com.iotp.controller.knowledge;

import com.iotp.entity.base.ResponseResult;
import com.iotp.entity.knowledge_type.KnowledgeType;
import com.iotp.service.knowledge_type.KnowledgeTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 知识库
 */
@RestController
public class KnowledgeController {
    private Logger logger = LoggerFactory.getLogger(KnowledgeController.class);

    @Autowired
    private KnowledgeTypeService knowledgeTypeService;//知识类别

    /**
     * 获取全部分类
     * @param type
     * @return
     */
    @PostMapping("/sys/knowledgeType/{type}")
    public ResponseResult knowledgeType(@PathVariable(value = "type", required = true) int type){
        return this.knowledgeTypeService.getAllNode(type);
    }

    /**
     * 添加根节点
     * @param knowledgeType
     * @return
     */
    @PostMapping("/sys/addRoot")
    public ResponseResult addRoot(KnowledgeType knowledgeType){
        return this.knowledgeTypeService.addRoot(knowledgeType);
    }

    /**
     * 节点操作
     * @param type              1：添加|编辑  2：删除
     * @param knowledgeType
     * @return
     */
    @PostMapping("/sys/editNode")
    public ResponseResult editNode(int type, KnowledgeType knowledgeType){
        return this.knowledgeTypeService.operationNode(type, knowledgeType);
    }

}
